package face.yuque;

/**
 * @author spf
 * @date 2024/12/11
 * @time 19:58
 */
// 删除有序数组中的重复项
// 双指针法
public class RemoveDulicate {
    public static void main(String[] args) {
        int[] nums = {0, 1, 1, 2, 2, 3, 4, 4, 5};
        System.out.println(countNums(nums));
    }

    private static int countNums(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }

        int slow = 0;
        for (int fast = 1; fast < nums.length; fast++) {
            if (nums[slow] != nums[fast]) {
                nums[++slow] = nums[fast];
            }
        }
        return slow + 1;
    }
}

